<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue</title>
    <script src="./vue.js"></script>
    <style>
        #root {
            width: 500px;
            margin: 200px auto;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="root">
        <button @click='addAtt'>点我增加属性</button>
        <button @click='add2'>点我增加属性</button>
    </div>
    <script>
        Vue.config.productionTip = false
        const vm = new Vue({
            el: '#root',
            data: {
                keyword: '',
                guas: {
                    name: '金瓜粒子',
                    price: '两块钱一斤',
                    id: '001'
                }
            },
            computed: {},
            watch: {},
            methods: {
                // 使用Vue.set来增加
                addAtt() {
                    Vue.set(vm._data.guas, 'brother', '吸铁石')
                        // Vue.set(vm.guas, 'brother', '吸铁石')
                        // Vue.set(this.guas, 'brother', '吸铁石')
                },
                //使用vm.$set来增加
                add2() {
                    vm.$set(vm._data.guas, 'toDo', '生意行')
                        // vm.$set(vm.guas, 'toDo', '生意行')
                        // vm.$set(this.guas, 'toDo', '生意行')
                        // this.$set(this.guas, 'toDo', '生意行')
                }
            },
        })
    </script>
</body>

</html>